package com.example.administrator.myfragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

/**
 * Created by wq on 2018/10/30.
 */
public class ThreeFragment extends Fragment {

    private TextView tv;
    private boolean ishidden = false;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View messageLayout = inflater.inflate(R.layout.fragment, container, false);
        tv = (TextView) messageLayout.findViewById(R.id.message);
        tv.setText("第三页");

        String message = getArguments().getString("message");
        Log.d("======ThreeFragment", message);

        return messageLayout;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
//        super.onHiddenChanged(hidden);
        ishidden = hidden;
        if (!hidden) {
            Log.d("=====ThreeFragment", "onHiddenChanged");
        }
    }

    /**
     * Fragment是否可见
     *
     * @return
     */
    public boolean isFragmentVisible() {
        if (!ishidden) {
            return true;
        }
        return false;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        Log.d("======ThreeFragment", "onAttach");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("======ThreeFragment", "onCreate");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("======ThreeFragment", "onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d("======ThreeFragment", "onResume");
        if (isFragmentVisible()) {  //
            Log.d("======ThreeFragment", "onResume=====================only");
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d("======ThreeFragment", "onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("======ThreeFragment", "onStop");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("======onDestroy", "onDestroy");
    }
}
